#include <signal.h>
#include <iostream>
using namespace std;

void Print()
{
    sigset_t pending;
    sigpending(&pending); // 获取当前信号的pending表
    cout << getpid() << ":";
    for (int i = 31; i >= 1; i--)
    {
        if (sigismember(&pending, i))
            cout << 1;
        else
            cout << 0;
    }
    cout << endl;
    sleep(5);
}

void handler(int sigon)
{
    cout << "获取到信号:" << sigon << endl;
    while (true)
    {
        Print();
    }
}

int main()
{
    struct sigaction act, oldact;
    act.sa_handler = handler;
    // 向sa_mask添加想要屏蔽的信号
    sigaddset(&act.sa_mask, 3);
    sigaddset(&act.sa_mask, 4);
    sigaction(2, &act, &oldact);
    while (true)
    {
        Print();
    }
}